package cn.yeziji.netty.config.mq;

import cn.yeziji.forum.common.key.RabbitMQConfig;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 通知消息处理
 *
 * @author gzkemays
 * @since 2022/11/22 9:27 PM
 */
@Configuration
public class NoticeMessageConfig {
  @Bean
  public Queue noticeMessageQueue() {
    return new Queue(RabbitMQConfig.NOTICE_MSG, true, false, false);
  }

  @Bean
  public DirectExchange noticeMessageDirectExchange() {
    // Direct交换机
    return new DirectExchange(RabbitMQConfig.NOTICE_MSG_EXCHANGE, true, false);
  }

  @Bean
  public Binding bindDirect() {
    // 链式写法，绑定交换机和队列，并设置匹配键
    return BindingBuilder
        // 绑定队列
        .bind(noticeMessageQueue())
        // 到交换机
        .to(noticeMessageDirectExchange())
        // 并设置匹配键
        .with(RabbitMQConfig.NOTICE_MSG_ROUTING_KEY);
  }
}
